package com.wuxi.zhang.design.factorypattern;

import java.util.Set;

/**
 * 找工作工厂类
 *
 * @author zhang on 2018/12/20.
 */
public class JobFactory {

    public static Job getJob(String name) {
        if (null == name) {
            return null;
        }
        //通过反射获取类名
        Set<String> classNames = PackageUtils.getClassName();
        for (String className : classNames){
            if (className.contains(name)) {
                Class clazz;
                try {
                    clazz = Class.forName(className);
                    Job job = (Job)clazz.newInstance();
                    return job;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}
